import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { ApiProvider } from '../../providers/api/api';
import {Res} from "../../modal/Res";
import {MainPage} from "../main/main";

/**
 * Generated class for the JoinCourseDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-join-course-detail',
  templateUrl: 'join-course-detail.html',
})
export class JoinCourseDetailPage {
  courseName;//课程名称
  className;//班级名称
  courseNum;//课程课程号
  teacherName;//教师名称

  classCourseId;//班课id
  studentId;//学生id
  teacherId;//教师id
  passwayState;//班课通道状态
  maxPersonNum;//班课最大人数

  constructor(public navCtrl: NavController, public navParams: NavParams,public http: ApiProvider) {
  }

  ionViewDidEnter() {
    this.courseName=this.navParams.get("courseName");
    this.teacherName=this.navParams.get("teacherName");
    this.className=this.navParams.get("className");
    this.courseNum=this.navParams.get("classNum");

    this.classCourseId=this.navParams.get("classcourseId");
    this.studentId=this.navParams.get("studentId");
    this.teacherId=this.navParams.get("teacherId");
    this.passwayState=this.navParams.get("passwayState");
    this.maxPersonNum=this.navParams.get("maxPersonNum");
  }

  /**
   * 加入课程
   */
  join()
  {
    this.http.post("/course/joinCourse.do",{classCourseId:this.classCourseId,
      studentId:this.studentId,teacherId:this.teacherId,passwayState:this.passwayState,maxPersonNum:this.maxPersonNum}).subscribe((item:Res)=>{
        if(item.Code=="11111111")
        {
          //this.http.errorAlert(item.Message);
          this.http.showToast(item.Message,'bottom');
        }
        else
        {
          this.navCtrl.push(MainPage);
        }
    })
  }
}
